<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('record列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>执行人：</label>
                                <input type="text" name="name"/>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:record:add">-->
<!--                    <i class="fa fa-plus"></i> 添加-->
<!--                </a>-->
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:record:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-primary" onclick="deduction()">
                    <i class="fa fa-credit-card"></i> 批量扣款
                </a>
                <a class="btn btn-primary" onclick="dedunotes()">
                    <i class="fa fa-credit-card"></i> 批量添加备注
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()">
                    <i class="fa fa-upload"></i> 导入扣款
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('execution:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('execution:record:remove')}]];
        var prefix = ctx + "execution/record";
        var cookie = ''
        var money = 100
        var flag = 0

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: "/api/new/importData",
                modalName: "record",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '执行人'
                },
                {
                    field: 'total',
                    title: '申请总条数'
                },
                {
                    field: 'successTotal',
                    title: '申请成功条数'
                },
                {
                    field: 'failTotal',
                    title: '申请失败条数'
                },
                    {
                        field: 'deductionSutotal',
                        title: '扣款成功条数'
                    },
                    {
                        field: 'deductionFautotal',
                        title: '扣款失败条数'
                    },
                    {
                        field: 'createTime',
                        title: '执行时间'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function Importdata(){

        }

        // 批量添加备注
        function dedunotes(){
            let lock = false

                layer.prompt({title: '请输入Cookie', formType: 2}, function (text, index) {
                    layer.close(index);
                    cookie = text.replace(/^\s+|\s+$/g, '')
                    lock = true;
                    if (lock) {
                        $.modal.loading("正在批量添加备注中，请稍后...");
                        $.ajax({
                            url: "/api/new/addNotes",
                            type: "post",
                            data: {
                                "cookie": cookie
                            },
                            success: res => {
                                $.modal.closeLoading();
                                if (res.code == "200") {
                                    $.modal.alertSuccess(res.msg)
                                    // $.modal.confirm(res.msg, function () {
                                    //     $.modal.msgReload("操作成功", modal_status.SUCCESS);
                                    // });
                                } else if (res.code == "500") {
                                    $.modal.alertWarning(res.msg)
                                    // $.modal.confirm(res.msg, function () {
                                    //     $.modal.msgReload("正在刷新数据", modal_status.SUCCESS);
                                    // });

                                }
                            }
                        })
                    }
            });
        }

        function deduction() {
            let lock = false
            layer.prompt({title: '请输入扣款金额', formType: 3}, function(pass, index) {
                layer.close(index);
                money = pass
                layer.prompt({title: '请输入Cookie', formType: 2}, function (text, index) {
                    layer.close(index);
                    cookie = text.replace(/^\s+|\s+$/g, '')
                    console.log(cookie)
                    lock = true;
                    if (lock) {
                        $.modal.loading("正在批量扣款中，请稍后...");
                        $.ajax({
                            url: "/api/new/deductionMain",
                            type: "post",
                            data: {
                                "cookie": cookie,
                                "Amount": money
                            },
                            success: res => {
                                $.modal.closeLoading();
                                console.log("成功")
                                console.log(res)
                                if (res.code == "200") {
                                    //$.modal.alertSuccess('操作成功！')
                                    $.modal.confirm(res.msg, function () {
                                        $.modal.msgReload("操作成功！正在刷新数据", modal_status.SUCCESS);
                                    });
                                } else if (res.code == "500") {
                                    //$.modal.alertWarning(res.msg)
                                    $.modal.confirm(res.msg, function () {
                                        $.modal.msgReload("正在刷新数据", modal_status.SUCCESS);
                                    });

                                }
                            }
                        })

                    }
                });
            });
        }
        function suc() {
            
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <span style="color:#ff0000;" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </span>
            <br/>
            <br/>
            <div>
                请输入cookie : &emsp;<input type="text" name="cookie" placeholder="请输入cookie">
            </div>
            <br>
            <div>
                <span>请输入扣款金额 : </span><input type="text" name="Amount" placeholder="请输入扣款金额">
            </div>
        </div>
    </form>
</script>
</html>